using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using SwinMessengerLibrary;

namespace SwinMessenger
{
    public partial class ServerPanel : UserControl
    {
        Server _Server;

        public Server Server
        {
            get { return _Server; }
        }

        public ServerPanel()
        {
            InitializeComponent();

            _Server = new Server();

            LoginButton.Enabled = false;
        }

        private void ServerPanel_Load(object sender, EventArgs e)
        {
            ServerTextBox.Focus();
        }

        private void LoginButton_Click(object sender, EventArgs e)
        {
            _Server.Hostname = ServerTextBox.Text;
            _Server.Username = UsernameTextBox.Text;
            _Server.Password = PasswordTextBox.Text;
            
            _Server.Login();
        }

        private void ServerTextBox_TextChanged(object sender, EventArgs e)
        {
            if (TestTextBoxes())
            {
                LoginButton.Enabled = true;
            }
        }

        private void UsernameTextBox_TextChanged(object sender, EventArgs e)
        {
            if (TestTextBoxes())
            {
                LoginButton.Enabled = true;
            }
        }

        private void PasswordTextBox_TextChanged(object sender, EventArgs e)
        {
            if (TestTextBoxes())
            {
                LoginButton.Enabled = true;
            }
        }

        private bool TestTextBoxes()
        {
            return !(ServerTextBox.Text.Equals("") ||
                UsernameTextBox.Text.Equals("") ||
                PasswordTextBox.Text.Equals(""));
        }
    }
}
